home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / rettig.arc / TRSOURCE.EXE / _TR_ISDR.ASM < prev    next >
Assembly Source File  |  1990-10-22  |  5KB  |  129 lines

  1. ; _TR_ISDR.ASM
  2. ;
  3. ; by Ralph Davis
  4. ; modified by Leonard Zerman
  5. ;
  6. ; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. ;
  8.  
  9.          PUBLIC   __TR_ISDR
  10.  
  11. DGROUP GROUP _DATA
  12. ;***************************************************
  13. _DATA  SEGMENT  WORD PUBLIC 'DATA'
  14.  
  15. ;
  16. FAT      DB     1024 DUP (?)  ; Buffer for disk read
  17. IS_DOS   DB     ?             ; Flag to indicate whether we use
  18.                               ; INT 25H (DOS) or INT 13H (ROM BIOS)
  19. ;
  20.  
  21. _DATA  ENDS
  22. ;***************************************************
  23.  
  24. ;***************************************************
  25. _TR_ISDR_TEXT SEGMENT  BYTE PUBLIC 'CODE'
  26.          ASSUME   CS:_TR_ISDR_TEXT,DS:_DATA
  27.  
  28. ;---------------------------------------------------
  29. ;
  30. ;   Syntax:  __ts_isdr( <drive> )
  31. ;   Return:  1 if drive exists and is ready
  32. ;            0 otherwise
  33. ;
  34. ;   Note:    This function uses INT 25H (absolute disk read)
  35. ;            or ROM BIOS INT 13H so as to avoid DOS 
  36. ;            "Abort, Retry, Ignore" messages.
  37. ;
  38. ;-----------------
  39. __TR_ISDR PROC  FAR
  40.          PUSH  BP               ; Save caller's BP
  41.          MOV   BP,SP            ; Address stack through BP
  42.          PUSH  SI               ; Save other registers
  43.          PUSH  DS
  44.          PUSH  ES
  45.          PUSH  DX
  46.          LDS   BX,[BP+6]        ; Get pointer to drive
  47.          MOV   DL,BYTE PTR [BX]    ; drive specifier in DL
  48.          AND   DL,0DFH          ; force to upper-case
  49.          CMP   DL,'B'           ; Greater than drive B?
  50.          JG    USE_DOS          ; Yes, use DOS INT 21H
  51.                                 ; Otherwise, use ROM BIOS INT 13H
  52.          SUB   DL,41H           ; convert to binary number
  53.          MOV   SI,3             ; We try to read the disk three times
  54.                                 ;   before reporting failure
  55. READ_DISK:
  56.          MOV   DH,0             ; head number 0
  57.          MOV   CH,0             ; track number 0
  58.          MOV   CL,1             ; start with sector number 1
  59.             MOV   AL,1                ; read 1 sectors
  60.          MOV   AH,2             ; request disk read
  61.          PUSH  AX
  62.          MOV   AX,_DATA         ; Point DS and ES to our data segment
  63.          MOV   DS,AX
  64.          MOV   ES,AX
  65.          POP   AX
  66.          AND   IS_DOS,0         ; Set DOS flag to false
  67.             MOV   BX,OFFSET FAT    ; address of buffer 
  68.          PUSHF                  ; Save flags (not necessary, done
  69.                                 ;   for code compatibility with DOS
  70.                                 ;   INT 25H)
  71.             INT   13H                 ; read the disk
  72.          JNC   GOODREAD         ; carry flag is error reporter
  73.          POPF                   ; Restore flags
  74.          DEC   SI               ; Try three times if unsuccessful
  75.          JNZ   READ_DISK
  76.             MOV   BX,0             ; for FALSE return
  77.          PUSH  BX               ; Save it till we need it
  78.          XOR   AX,AX            ; floppy disk service 0
  79.          INT   13h              ; reset disk drive
  80.             JMP   SHORT EXIT
  81.  
  82. USE_DOS: MOV   AL,DL            ; Drive letter to AL
  83.          SUB   AL,41H           ; Convert to binary
  84.          MOV   CX,1             ; Starting sector number
  85.          MOV   DX,2             ; Read two sectors
  86.          PUSH  AX            
  87.          MOV   AX,_DATA         ; Point DS to our data segment
  88.          MOV   DS,AX
  89.          POP   AX
  90.          MOV   BX,OFFSET FAT    ; Point BX to input buffer
  91.          OR    IS_DOS,0FFH      ; Turn on DOS flag
  92.          PUSHF                  ; Save flags--INT 25H doesn't POP them
  93.          INT   25H
  94.          JNC   GOODREAD
  95.          POPF                   ; Restore flags
  96.          ADD   SP,2             ; Restore stack
  97.          MOV   BX,0             ; For FALSE return
  98.          PUSH  BX               ; Save it for later
  99.          JMP   SHORT EXIT
  100. ;
  101. GOODREAD:
  102.          POPF                   ; Restore flags
  103.          CMP   IS_DOS,0FFH      ; Did we do INT 25H or INT 13H?
  104.          JNE   GR_2             ; INT 13H
  105.          ADD   SP,2             ; Restore stack
  106. GR_2:
  107.          MOV    BX,1            ; for TRUE return
  108.          PUSH   BX              ; Save it for later
  109.  
  110. EXIT:    CMP    IS_DOS,0FFH     ; DOS or ROM BIOS?
  111.          JNE    EXIT_2          ; ROM BIOS
  112.          MOV    AH,0DH          ; Reset disk status if DOS
  113.          INT    21H
  114. EXIT_2:
  115.          POP    BX              ; Retrieve TRUE or FALSE result
  116.          MOV    AX,BX           ; Place it in AX ax return value
  117.          POP    DX
  118.          POP    ES              ; Restore registers
  119.          POP    DS
  120.          POP    SI
  121.          POP    BP
  122.          RET
  123. __TR_ISDR ENDP
  124. ;-----------------------------------------------------------
  125. _TR_ISDR_TEXT    ENDS
  126. ;*************************************************************
  127.          END  
  128.  
  129.